const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// 路由模型
const RouterSchema = new Schema({
  title: {
    type: String, // 标题
    required: true,
  },
  type: {
    type: Number, // 跳转还是外链
    required: true,
    default: 0, // 1 是link 0是页面跳转
  },
  menuType: {
    type: Number, // 跳转还是外链
    default: 0, // 导航 1 菜单
  },
  path: {
    type: String, // 路径
  },
  icon: {
    type: String,
  },
  // 关联角色
  auth: [
    {
      type: Number,
    },
  ],

  meta: {
    title: {
      type: String, // 页面标题
    },
    keepAlive: {
      type: Boolean,
      default: false, // 是否缓存
    },
    hidden: {
      type: Boolean, // 是否隐藏
      default: false,
    },
  },
  component: {
    type: String, // 组件
    required: false,
    default: null,
  },
  parentId: {
    type: Schema.Types.ObjectId, // 关联父节点ID
    required: false,
  },
});

const RouterModel = mongoose.model('routers', new Schema(RouterSchema));

module.exports = RouterModel;
